<template>
    <div class="alllook-background">
        <main v-if="isShow" style="background:white;border:solid 2px darkgrey;height:70px;-webkit-box-direction: none;text-align: center;line-height:70px;">
        实践名称：<el-input v-model="NewName" placeholder="请输入实践名称" style="width:200px"></el-input>
        &nbsp;&nbsp;实践地址：<el-input v-model="NewAddress" placeholder="请输入实践地址" style="width:200px"></el-input>
        &nbsp;&nbsp;开始时间：<el-input v-model="NewStartTime" placeholder="请输入开始时间" style="width:200px"></el-input>
        &nbsp;&nbsp;结束时间：<el-input v-model="NewEndTime" placeholder="请输入结束时间" style="width:200px"></el-input>
        <el-button type="success" icon="el-icon-check" circle size="mini" style="margin-left:20px" @click="submit"></el-button>
        </main>
        <el-table
    :data="tableData"
    height="600"
    stripe
    border
    highlight-current-row
    v-loading="loading"
    style="width: 100%">
    <el-table-column
    prop="p_id"
    label="实践序号"
    width="190"
    >
    </el-table-column>
    <el-table-column
    prop="p_name"
    label="实践名称"
    width="190">
    </el-table-column>
    <el-table-column
    prop="address"
    label="实践地址"
    width="190">
    </el-table-column>
    <el-table-column
    prop="teacher.teacher_name"
    label="负责老师"
    width="190">
    </el-table-column>
    <el-table-column
    prop="start_time"
    label="起始时间"
    width="190">
    </el-table-column>
    <el-table-column
    prop="end_time"
    label="结束时间"
    width="190">
    </el-table-column>
    <el-table-column
      label="操作"
      width="125">
      <template slot-scope="scope">
        <el-button @click="show(scope.$index,scope.row)" type="text" size="small">修改</el-button>
      </template>
    </el-table-column>
  </el-table>
    </el-table>
    <el-button type="warning" icon="el-icon-refresh-right" circle @click="refresh"></el-button>
    </div>
       
  
</template>

<script>
export default {
    data(){
        return {
        tableData: [],
        teacher:JSON.parse(sessionStorage.getItem('teacher')),
        NewName:'',
        NewAddress:'',
        NewStartTime:'',
        NewEndTime:'',
        revisep_id:'',
        isShow:false,
        loading:false
    };
    },
    created(){
        this.$axios.post('/api/teacher/selectpractice',this.$qs.stringify({t_id:this.teacher.t_id})).then(res=>{
            this.tableData=res.data;
        })
    },
    methods:{
        show(index,row){
            this.isShow=!this.isShow;
            this.revisep_id=row.p_id;
        },
        submit(){
            this.$axios.post('/api/teacher/updatepractice',this.$qs.stringify({
                p_id:this.revisep_id,
                p_name:this.NewName,
                address:this.NewAddress,
                t_id:this.teacher.t_id,
                start_time:this.NewStartTime,
                end_time:this.NewEndTime})).then((res)=>{
                    this.$message.success('修改成功');
                    this.isShow=!this.isShow;
                    this.NewName='';
                    this.NewAddress='';
                    this.NewStartTime='';
                    this.NewEndTime='';
                }).catch(()=>{
                    this.$$message.error('修改失败')
                })
        },
        refresh(){
            this.loading=true;
            setTimeout(()=>{
                this.loading=false;
            },1000)
            this.$axios.post('/api/teacher/selectpractice',this.$qs.stringify({t_id:this.teacher.t_id})).then(res=>{
            this.tableData=res.data;
        })
        }
    }
    
    
}
</script>

<style>
.table{
    cursor: pointer;
    font-size:20px;
}
alllook-background{
    padding: 10px;
    font-size: 16px;
    box-shadow:5px 5px 20px gainsboro;
}
</style>